﻿using System;
using System.Text;

namespace Duo1JHttpServer.Framework.Utils
{
    /// <summary>
    /// 控制台输出工具
    /// </summary>
    public class ConsoleUtils
    {
        /// <summary>
        /// 输出带颜色字符串到控制台
        /// </summary>
        public static void WriteColorLine(string str, ConsoleColor color)
        {
            ConsoleColor curForeColor = Console.ForegroundColor;
            Console.ForegroundColor = color;
            Console.WriteLine(str);
            Console.ForegroundColor = curForeColor;
        }

        /// <summary>
        /// 输出黄色行到控制台
        /// </summary>
        public static void WriteYellowLine(string str)
        {
            WriteColorLine(str, ConsoleColor.Yellow);
        }

        /// <summary>
        /// 输出红色行到控制台
        /// </summary>
        public static void WriteRedLine(string str)
        {
            WriteColorLine(str, ConsoleColor.Red);
        }

        /// <summary>
        /// 输出蓝色行到控制台
        /// </summary>
        public static void WriteBlueLine(string str)
        {
            WriteColorLine(str, ConsoleColor.Blue);
        }

        /// <summary>
        /// 输出绿色行到控制台
        /// </summary>
        public static void WriteGreenLine(string str)
        {
            WriteColorLine(str, ConsoleColor.Green);
        }

        /// <summary>
        /// 输出开头带水平制表符字符串到控制台
        /// </summary>
        /// <param name="tabCount">水平制表符数目，默认1</param>
        public static void WriteTabLine(string str, int tabCount = 1)
        {
            string tabStr = "\t";
            if (tabCount != 1)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < tabCount; i++)
                {
                    sb.Append("\t");
                }

                tabStr = sb.ToString();
            }

            Console.WriteLine($"{tabStr}{str}");
        }
    }
}